export const GET_USER_INFO_REQUEST = 'GET_USER_INFO_REQUEST'
export const GET_USER_INFO_SUCCESS = 'GET_USER_INFO_SUCCESS'
export const GET_USER_INFO_FAILURE = 'GET_USER_INFO_FAILURE'


export function getUserInfoRequest() {
    return {
        type: GET_USER_INFO_REQUEST
    }
}

export function getUserInfoSuccess(userInfo) {
    return {
        type: GET_USER_INFO_SUCCESS,
        userInfo: userInfo
    }
}

export function getUserInfoFailure(error) {
    return {
        type: GET_USER_INFO_FAILURE,
        error: error
    }
}

export function getUserInfo() {
    return function(dispatch){
        dispatch(getUserInfoRequest);

        return fetch('/api/data.json',{
                   mode: 'no-cors'
               })
               .then((res) => {
                   return res.json();
               })
               .then((res) => {
                    dispatch(getUserInfoSuccess(res));
               })
               .catch((e) => {
                   dispatch(getUserInfoFailure(e));
               })
    }
}